package day02;

/**
 * @author Jetwang
 * @version 1.0
 * @since 2023/2/25 20:54
 */
public class LinearSearch {
    public static void main(String[] args) {
        int[] arr = { 1, 4, 6, 8, 10 };
        int index = linearSearch(arr, 3);
    }

    /**
     * 线性查找
     * @param arr
     * @param target
     * @return
     */
    private static int linearSearch(int[] arr, int target) {
        for (int i = 0; i < arr.length; i++) {
            if (target == arr[i]) {
                return i;
            }
        }
        return -1;
    }
}
